//
//  HYReceivedCell.m
//  HaiYue
//
//  Created by skyline on 2018/1/12.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYReceivedCell.h"
@interface HYReceivedCell()
@property (nonatomic, strong) HYImageView *backIMG;
@property (nonatomic, strong) HYLabel *tipsLBL;
@property (nonatomic, strong) HYImageView *IMG;
@property (nonatomic, strong) HYLabel *titleLBL;
@property (nonatomic, strong) HYLabel *typeLBL;
@property (nonatomic, strong) HYFillLabel *discountLBL;
@end
@implementation HYReceivedCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.style = HYReceivedCellDefaultStyle;
    }
    return self;
}

- (void)setStyle:(HYReceivedCellStyle)style
{
    if (_style != style)
    {
        _style = style;
        self.layer.cornerRadius = GAP;
        self.layer.borderWidth = 0.5;
        self.layer.masksToBounds = (_style == HYReceivedCellDefaultStyle)?YES:NO;
        self.layer.borderColor = (_style == HYReceivedCellDefaultStyle)?CELL_LINE_COLOR.CGColor:[UIColor clearColor].CGColor;
        self.backgroundColor = (_style == HYReceivedCellDefaultStyle)?[UIColor whiteColor]:[UIColor clearColor];
        self.backIMG.hidden = self.tipsLBL.hidden = (_style == HYReceivedCellDefaultStyle)?YES:NO;
        self.IMG.hidden = self.titleLBL.hidden = self.typeLBL.hidden = self.discountLBL.hidden = !self.backIMG.hidden;
        if (self.IMG.hidden == NO)
        {
            self.IMG.image = [UIImage imageNamed:@"3"];
            self.titleLBL.text = @"攻城三国-三国演义";
            self.typeLBL.text = @"策略";
            self.discountLBL.text = @"4.2折";
        }
    }
}

- (HYImageView *)backIMG
{
    if (!_backIMG)
    {
        _backIMG = [[HYImageView alloc]initWithImage:[UIImage imageNamed:@"4"]];
        [self addSubview:_backIMG];
    }
    CGFloat bottom = (_style == HYReceivedCellDefaultStyle)?0:100;
    [_backIMG mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(0, 0, bottom, 0));
    }];
    return _backIMG;
}

- (HYLabel *)tipsLBL
{
    if (!_tipsLBL)
    {
        _tipsLBL = [[HYLabel alloc] initWithText:@"有以下游戏提供补偿礼包" textColor:THEME_COLOR textFont:[UIFont systemFontOfSize:13 weight:UIFontWeightLight]];
        [self addSubview:_tipsLBL];
        [_tipsLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.centerX.equalTo(self);
        }];
    }
    return _tipsLBL;
}

- (HYImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[HYImageView alloc] initWithCornerRadius:GAP];
        [self addSubview:_IMG];
        [_IMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
            make.bottom.equalTo(self).with.offset(- GAP);
            make.width.mas_equalTo(HYReceivedCellHeight - GAP * 2);
        }];
    }
    return _IMG;
}

- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[HYLabel alloc]initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:13]];
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.IMG);
            make.left.equalTo(self.IMG.mas_right).with.offset(GAP / 2.0);
        }];
    }
    return _titleLBL;
}

- (HYLabel *)typeLBL
{
    if (!_typeLBL)
    {
        _typeLBL = [[HYLabel alloc]initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:11 weight:UIFontWeightLight]];
        [self addSubview:_typeLBL];
        [_typeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.IMG);
            make.left.equalTo(self.IMG.mas_right).with.offset(GAP / 2.0);
        }];
    }
    return _typeLBL;
}

- (HYFillLabel *)discountLBL
{
    if (!_discountLBL)
    {
        _discountLBL = [[HYFillLabel alloc]initWithFrame:CGRectMake(0, 0, 35, 20) typeOfshapeLayer:CCShapeLayerTypeEllipse attribute:@{HYTextColor:[UIColor whiteColor],HYTextFont:[UIFont systemFontOfSize:11],HYBorderColor:ORANGE_COLOR,HYLayerColor:ORANGE_COLOR}];
        [self addSubview:_discountLBL];
        [_discountLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.typeLBL.mas_right).with.offset(GAP / 2.0);
            make.centerY.equalTo(self.typeLBL);
            make.size.mas_equalTo(self.discountLBL.bounds.size);
        }];
    }
    return _discountLBL;
}
@end
